//
//
//  InfdetailsViewController.m
//  MidProject
//
//  Created by itlab on 2020/11/15.
//  Copyright © 2020 itlab. All rights reserved.
//


#import <Foundation/Foundation.h>
#import "InfdetailsViewController.h"
#import "ImgDetailViewController.h"

CGFloat img_start_pos_x = 20;
CGFloat img_start_pos_y = 300;
CGFloat img_offset_x = 90;
CGFloat img_offset_y = 90;
CGFloat img_height = 80;
CGFloat img_width = 80;


UIButton *collectBtn, *likeBtn;
NSInteger addLikeNum = 0;
NSString *pageId;
NSMutableArray *pos; //image pos
NSError *jsonError;
NSDictionary *pageInfo;
NSDictionary *commentInfo;
NSMutableArray *data_list;



@interface InfdetailsViewController() <UITableViewDelegate, UISearchBarDelegate, CAAnimationDelegate, UITableViewDataSource>

@property (strong, nonatomic) card_info *tar_card;
@property(strong, nonatomic) UIScrollView *scrollView;
@property (nonatomic, strong) UIImageView *ivUser;
@property (nonatomic, strong) UILabel *lName;
@property (nonatomic, strong) UILabel *lTime;
@property (nonatomic, strong) UILabel *lTitle;
@property (nonatomic, strong) UILabel *lContent;
@property (nonatomic, strong) SquareTableImgView *fcIView;
@property (nonatomic, strong) UIView *helpView;
@property (nonatomic, strong) UIImageView *likeimage;
@property (nonatomic, strong) UILabel *likenum;
@property (nonatomic, strong) UIImageView *commentimage;
@property (nonatomic, strong) UILabel *commentnum;
@property (nonatomic, strong) UITableView *comment_tableView;
@property (nonatomic, strong) UIButton *like_button;
@property (nonatomic, strong) UIButton *fav_button;
@property (nonatomic, strong) UIButton *comment_button;
@property (nonatomic, strong) NSMutableArray *img_set;
@property (nonatomic, assign) Boolean like_state;
@property (nonatomic, assign) Boolean fav_state;
@property (nonatomic, strong) NSMutableArray* img_set_url;
- (void)viewDidLoad:(NSString*) card_id;


@end

@implementation InfdetailsViewController

// Set button event
- (void)popToCardTable:(UIBarButtonItem *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

// Set the gradient color from top left to bottom right
-(UIImage *)gradientColorImageFromColors:(NSArray*)colors imgSize:(CGSize)imgSize {
    NSMutableArray *ar = [NSMutableArray array];
    for (UIColor *c in colors) [ar addObject:(id)c.CGColor];
    UIGraphicsBeginImageContextWithOptions(imgSize, YES, 1);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    CGColorSpaceRef colorSpace = CGColorGetColorSpace([[colors lastObject] CGColor]);
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)ar, NULL);
    CGPoint begin, end;
    begin = CGPointMake(0, 0);
    end = CGPointMake(imgSize.width, imgSize.height);
    CGContextDrawLinearGradient(context, gradient, begin, end, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    CGGradientRelease(gradient);
    CGContextRestoreGState(context);
    CGColorSpaceRelease(colorSpace);
    UIGraphicsEndImageContext();
    return image;
}

#pragma mark - TableView
-(UITableView *)tableView{
    if (!_comment_tableView) {
        _comment_tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _comment_tableView.delegate = self;
        _comment_tableView.dataSource = self;
        _comment_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _comment_tableView.backgroundColor = [UIColor whiteColor];
    }
    return _comment_tableView;
}


#pragma mark - TableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return data_list.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

// Event triggered when a row is selected
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"6666");
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"回复" message:data_list[indexPath.row] preferredStyle:UIAlertControllerStyleAlert];
    //
    //    //增加取消按钮；
    //    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
    //    //增加确定按钮；
    //    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    //        //获取第1个输入框；
    //        UITextField *userCommentTextField = alertController.textFields.firstObject;
    //        NSLog(@"回复 = %@",userCommentTextField.text);
    //        int spaceIndex = 0;
    //        for (int i = 0; i < [data_list[indexPath.row] length];i++) {
    //            if ([[data_list[indexPath.row] substringWithRange:NSMakeRange(i,1)]  isEqual: @" "]) {
    //                spaceIndex = i;
    //                break;
    //            }
    //        }
    //        [data_list addObject:[NSString stringWithFormat:@"我 回复 %@: %@", [data_list[indexPath.row] substringToIndex:spaceIndex],  userCommentTextField.text]];
    //        [tableView reloadData];
    //    }]];
    //    //定义第一个输入框；
    //    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
    //        textField.placeholder = @"请输入文字";
    //    }];
    //
    //    [self presentViewController:alertController animated:true completion:nil];
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"回复" message:data_list[indexPath.row] preferredStyle:UIAlertControllerStyleAlert];
    //增加确定按钮；
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //获取第1个输入框；
        UITextField *userCommentTextField = alertController.textFields.firstObject;
        NSLog(@"回复 = %@",userCommentTextField.text);
        int spaceIndex = 0;
        for (int i = 0; i < [data_list[indexPath.row] length];i++) {
            if ([[data_list[indexPath.row] substringWithRange:NSMakeRange(i,1)]  isEqual: @" "]) {
                spaceIndex = i;
                break;
            }
        }
        NSDictionary *res = @{@"contentID": commentInfo[@"Data"][indexPath.row][@"Comment"][@"ID"], @"fatherID":commentInfo[@"Data"][indexPath.row][@"Comment"][@"UserID"], @"content": userCommentTextField.text, @"isReply": @YES};
        puts("_________________________");
        NSLog(@"%@", res);
        //    NSDictionary *text = [[NSDictionary alloc] initWithObjectsAndKeys: @"这是一个测试", @"title", @"天长地久有时尽，此恨绵绵无绝期" , @"detail",@"学习",@"tag",nil ];
        NSString *urlStr = @"http://172.18.178.56/api/comment";
        NSString *urlString = [NSString stringWithFormat:@"%@",urlStr];
        NSURL *url = [NSURL URLWithString:urlString];
        NSError *error;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:NSJSONWritingPrettyPrinted error:&error];
        
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
        [request setHTTPMethod:@"POST"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [request setValue:[NSString stringWithFormat:@"%lu",(unsigned long)[jsonData length]] forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:jsonData];
        NSURLSession *session = [NSURLSession sharedSession];
        dispatch_semaphore_t semaphore= dispatch_semaphore_create(0);
        NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                                    completionHandler:^(NSData *return_data, NSURLResponse *response, NSError *error) {
                                                        
                                                        NSError *jsonError;
                                                        NSDictionary *jsonDictionaryOrArray = [NSJSONSerialization JSONObjectWithData:return_data options:kNilOptions error:&jsonError];
                                                        
                                                        NSLog(@"!!!!49635698354\n%@",jsonDictionaryOrArray);
                                                        
                                                        if(jsonError) {
                                                            // check the error description
                                                            NSLog(@"json error : %@", [jsonError localizedDescription]);
                                                        } else {
                                                            // use the jsonDictionaryOrArray
                                                            if ([jsonDictionaryOrArray[@"State"]  isEqual: @"success"]) {
                                                                NSLog(@"json : success");
                                                                //                    dispatch_async(dispatch_get_main_queue(), ^{
                                                                //                        NSLog(@"!!!!kha-zix%@\n", pageId);
                                                                //                    });
                                                                
                                                            } else {
                                                                NSLog(@"json : error");
                                                            }
                                                        }
                                                        dispatch_semaphore_signal(semaphore);
                                                    }];
        [dataTask resume];
        dispatch_semaphore_wait(semaphore,DISPATCH_TIME_FOREVER);
        
        
        //        [data_list removeObject:data_list[data_list.count - 1]];
        [data_list addObject:[NSString stringWithFormat:@"我 回复 %@: %@", [data_list[indexPath.row] substringToIndex:spaceIndex],  userCommentTextField.text]];
        //        [data_list addObject:[NSString stringWithFormat:@"评论"]];
        [tableView reloadData];
    }]];
    
    //增加取消按钮；
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
    
    //定义第一个输入框；
    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"请输入文字";
    }];
    
    [self presentViewController:alertController animated:true completion:nil];
}

- (UITableViewCell *)tableView:(UITableViewCell *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CommentTableViewCell *cell = [[CommentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.layer.cornerRadius = 0;
    cell.textLabel.numberOfLines = 0;
    //Set to transparent here is to be able to display the gradient color of the background, otherwise it will cover the color of the background
    cell.backgroundColor = [UIColor clearColor];
    NSString *model = data_list[indexPath.section];
    [cell setModel:model];
    return cell;
}

#pragma mark - TableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat height = [CommentTableViewCell hyb_heightForTableView:tableView config:^(UITableViewCell *sourceCell) {
        CommentTableViewCell *regCell = (CommentTableViewCell *)sourceCell;
        // 配置数据
        NSString *model = data_list[indexPath.section];
        NSLog(@"bejing2: %@", [[NSString alloc] initWithFormat:@"%@", model]);
        [regCell setModel:model];
        
    } cache:^NSDictionary *{
        return @{kHYBCacheUniqueKey: [NSString stringWithFormat:@"%ld",indexPath.section],
                 kHYBCacheStateKey : @"cell",
                 // 如果设置为YES，若有缓存，则更新缓存，否则直接计算并缓存s
                 // 主要是对社交这种有动态评论等不同状态，高度也会不同的情况的处理
                 kHYBRecalculateForStateKey : @(NO) // 标识要重新更新
                 };
    }];
    return height;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0001;
}



- (void)tapAction
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

- (void)imgDetailLoad:(UITapGestureRecognizer *)gesture {
    puts("????????");
    ImgDetailViewController *detailVC = [[ImgDetailViewController alloc] init];
    puts("????????");
    [detailVC viewDidLoad: _img_set_url];
    [self.navigationController pushViewController:detailVC animated:NO];
}

// set page information
- (void)setInfoByJson:(NSDictionary *)jsonDictionaryOrArray{
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    [self.scrollView setScrollEnabled:YES];
    
    // head image
    _ivUser = [UIImageView new];
    _ivUser.clipsToBounds = YES;
    _ivUser.contentMode = UIViewContentModeScaleAspectFill;
    [self.scrollView addSubview:_ivUser];
    [_ivUser mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(20);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    _ivUser.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"login.png"] TransformtoSize:CGSizeMake(40, 40)]];
    
    //用户名
    _lName = [UILabel new];
    _lName.textColor = [UIColor grayColor];
    _lName.textAlignment = NSTextAlignmentLeft;
    _lName.font = [UIFont systemFontOfSize:14];
    [self.scrollView addSubview:_lName];
    [_lName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.ivUser.mas_right).offset(10);
        make.top.mas_equalTo(self.ivUser.mas_top);
        make.height.mas_equalTo(20);
        make.right.mas_equalTo(self.scrollView.mas_right).offset(-20);
    }];
    _lName.text = [NSString stringWithFormat:@"%@", jsonDictionaryOrArray[@"User"][@"Name"]];
    
    //时间
    _lTime = [UILabel new];
    _lTime.textColor = [UIColor lightGrayColor];
    _lTime.textAlignment = NSTextAlignmentLeft;
    _lTime.font = [UIFont systemFontOfSize:12];
    [self.scrollView addSubview:_lTime];
    [_lTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.lName.mas_left);
        make.top.mas_equalTo(self.lName.mas_bottom).offset(5);
        make.height.mas_equalTo(10);
    }];
    NSString *temp_public_time_s = [NSString stringWithFormat:@"%@", jsonDictionaryOrArray[@"Data"][@"PublishDate"]];
    NSTimeInterval time = [temp_public_time_s doubleValue];
    NSDate *detaildate = [NSDate dateWithTimeIntervalSince1970:time/1000];
    NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
    [formatter setTimeZone:timeZone];
    NSString *temp_public_time = [formatter stringFromDate:detaildate];
    _lTime.text = [NSString stringWithFormat:@"%@", temp_public_time];
    
    // title
    _lTitle = [UILabel new];
    _lTitle.textColor = [UIColor blackColor];
    _lTitle.textAlignment = NSTextAlignmentLeft;
    _lTitle.font = [UIFont systemFontOfSize:20];
    _lTitle.numberOfLines = 0;
    [self.scrollView addSubview:_lTitle];
    [_lTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.lName.mas_left);
        make.top.mas_equalTo(self.lTime.mas_bottom).offset(10);
        make.right.mas_equalTo(self.scrollView.mas_right).offset(-20);
    }];
    _lTitle.text = [NSString stringWithFormat:@"%@", jsonDictionaryOrArray[@"Data"][@"Name"]];
    
    //内容
    _lContent = [UILabel new];
    _lContent.textColor = [UIColor blackColor];
    _lContent.textAlignment = NSTextAlignmentLeft;
    _lContent.font = [UIFont systemFontOfSize:14];
    _lContent.numberOfLines = 0;
    [self.scrollView addSubview:_lContent];
    //最大宽度
    _lContent.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - 90;
    [_lContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.lName.mas_left);
        make.top.mas_equalTo(self.lTitle.mas_bottom).offset(10);
        make.right.mas_equalTo(self.scrollView.mas_right).offset(-20);
    }];
    _lContent.text = [NSString stringWithFormat:@"%@", jsonDictionaryOrArray[@"Data"][@"Detail"]];
    
    dispatch_semaphore_t semaphore= dispatch_semaphore_create(0);
    //评论区的处理
    NSString *urlString = [NSString stringWithFormat:@"%@%@", @"http://172.18.178.56/api/comment/", jsonDictionaryOrArray[@"Data"][@"ID"]];
    //NSString *urlString = @"http://172.18.178.56/api/comment/5fc788c1f5beb2def128d5ca";
    
    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"GET";
    request.timeoutInterval = 60;
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                    NSError *jsonError;
                                                    NSDictionary *jsonDictionaryOrArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];
                                                    if(jsonError) {
                                                        // check the error description
                                                        NSLog(@"json error : %@", [jsonError localizedDescription]);
                                                    } else {
                                                        // use the jsonDictionaryOrArray
                                                        //NSLog(@"json : %@",jsonDictionaryOrArray);
                                                        commentInfo = jsonDictionaryOrArray;
                                                        
                                                    }
                                                    dispatch_semaphore_signal(semaphore);
                                                }];
    [dataTask resume];
    dispatch_semaphore_wait(semaphore,DISPATCH_TIME_FOREVER);
    
    NSArray *items = [[[jsonDictionaryOrArray valueForKeyPath:@"Data"] valueForKeyPath:@"Album"] valueForKeyPath:@"Images"];
    NSInteger photoNum = items.count;
    NSLog(@"%ld", photoNum);
    _img_set = [[NSMutableArray alloc] initWithCapacity:photoNum];
    _img_set_url = [[NSMutableArray alloc] init];
    for (int i = 0; i < photoNum; i++) {
        NSString* image_path = [NSString stringWithFormat:@"%@%@",@"http://172.18.178.56/api/thumb/", jsonDictionaryOrArray[@"Data"][@"Album"][@"Images"][i][@"Thumb"]];
        NSLog(@"%@\n", image_path);
        [_img_set_url addObject:image_path];
        NSData *data = [NSData dataWithContentsOfURL:[NSURL  URLWithString:image_path]];
        UIImage *image = [UIImage imageWithData:data]; // 取得图片
        [_img_set addObject:image];
    }
    
    _fcIView = [[SquareTableImgView alloc]initWithMaxWidth:[UIScreen mainScreen].bounds.size.width - 90];
    [self.scrollView addSubview:_fcIView];
    [_fcIView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.lContent.mas_left);
        make.top.mas_equalTo(self.lContent.mas_bottom).offset(20);
        make.right.mas_equalTo(self.lContent.mas_right);
    }];
    [_fcIView setButtonCount: photoNum
                     withImg: _img_set];
    
    _helpView = [[UIView alloc]init];
    _helpView.backgroundColor = UIColor.clearColor;
    [self.scrollView addSubview:_helpView];
    [_helpView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.fcIView.mas_left);
        make.top.mas_equalTo(self.fcIView.mas_top);
        make.right.mas_equalTo(self.fcIView.mas_right);
        make.bottom.mas_equalTo(self.fcIView.mas_bottom);
    }];
    _helpView.userInteractionEnabled = YES;
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgDetailLoad:)];
    [_helpView addGestureRecognizer:tapGesture];
    [tapGesture setNumberOfTapsRequired:1];
    
    // 点赞框
    _likeimage = [UIImageView new];
    _likeimage.contentMode = UIViewContentModeScaleAspectFill;
    _like_state = [self get_like_state];
    [self.scrollView addSubview:_likeimage];
    [_likeimage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.fcIView.mas_left);
        make.top.mas_equalTo(self.fcIView.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(20 , 20));
    }];
    _likeimage.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"like.png"] TransformtoSize:CGSizeMake(20, 20)]];
    //    UITapGestureRecognizer *tapGesture_like = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clicklikeimage)];
    //    [_likeimage addGestureRecognizer:tapGesture_like];
    //    _likeimage.userInteractionEnabled = YES;
    
    
    // 点赞数
    _likenum = [UILabel new];
    _likenum.contentMode = NSTextAlignmentLeft;
    [self.scrollView addSubview:_likenum];
    [_likenum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.fcIView.mas_left).offset(50);
        make.top.mas_equalTo(self.fcIView.mas_bottom).offset(20);
    }];
    _likenum.text = [NSString stringWithFormat:@"%@", jsonDictionaryOrArray[@"Data"][@"LikeNum"]];
    
    _commentimage = [UIImageView new];
    _commentimage.contentMode = UIViewContentModeScaleAspectFill;
    [self.scrollView addSubview:_commentimage];
    [_commentimage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.fcIView.mas_left).offset(100);
        make.top.mas_equalTo(self.fcIView.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    _commentimage.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"comment.png"] TransformtoSize:CGSizeMake(20, 20)]];
    
    _commentnum = [UILabel new];
    _commentnum.contentMode = NSTextAlignmentLeft;
    [self.scrollView addSubview:_commentnum];
    [_commentnum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.fcIView.mas_left).offset(150);
        make.top.mas_equalTo(self.fcIView.mas_bottom).offset(20);
    }];
    _commentnum.text = [NSString stringWithFormat:@"%@", jsonDictionaryOrArray[@"Data"][@"CommentNum"]];
    
    _like_button = [UIButton new];
    _like_button.contentMode = NSTextAlignmentLeft;
    _like_button.backgroundColor = [UIColor colorWithRed:135/255.0 green:206/255.0 blue:250/255.0 alpha:0.2];
    _like_button.frame = CGRectMake(0, 0, (self.scrollView.frame.size.width / 3) - 40, 30);
    [_like_button setTitle:@"点赞" forState:UIControlStateNormal];
    [_like_button setTitleColor:[UIColor colorWithRed:25/255.0 green:25/255.0 blue:112/255.0 alpha:1.0] forState:UIControlStateNormal];
    UIBezierPath * maskPath_like = [UIBezierPath bezierPathWithRoundedRect:_like_button.bounds cornerRadius:10];
    CAShapeLayer * maskLayer_like = [[CAShapeLayer alloc] init];
    maskLayer_like.frame = _like_button.bounds;
    maskLayer_like.path = maskPath_like.CGPath;
    _like_button.layer.mask = maskLayer_like;
    [_like_button addTarget:self
                     action:@selector(clicklikeimage:)
           forControlEvents:UIControlEventTouchUpInside];
    [self.scrollView addSubview:_like_button];
    [_like_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.ivUser.mas_left).offset(20);
        make.top.mas_equalTo(self.commentnum.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake((self.scrollView.frame.size.width / 3) - 40, 30));
    }];
    
    _fav_button = [UIButton new];
    _fav_button.contentMode = NSTextAlignmentLeft;
    _fav_button.frame = CGRectMake(0, 0, (self.scrollView.frame.size.width / 3) - 40, 30);
    _fav_button.backgroundColor = [UIColor colorWithRed:135/255.0 green:206/255.0 blue:250/255.0 alpha:0.2];
    [_fav_button setTitle:@"收藏" forState:UIControlStateNormal];
    [_fav_button setTitleColor:[UIColor colorWithRed:25/255.0 green:25/255.0 blue:112/255.0 alpha:1.0] forState:UIControlStateNormal];
    UIBezierPath * maskPath_fav = [UIBezierPath bezierPathWithRoundedRect:_fav_button.bounds cornerRadius:10];
    CAShapeLayer * maskLayer_fav = [[CAShapeLayer alloc] init];
    maskLayer_fav.frame = _fav_button.bounds;
    maskLayer_fav.path = maskPath_fav.CGPath;
    _fav_button.layer.mask = maskLayer_fav;
    [_fav_button addTarget:self
                    action:@selector(clickfavimage:)
          forControlEvents:UIControlEventTouchUpInside];
    [self.scrollView addSubview:_fav_button];
    [_fav_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.like_button.mas_right).offset(30);
        make.top.mas_equalTo(self.commentnum.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake((self.scrollView.frame.size.width / 3) - 40, 30));
    }];
    
    _comment_button = [UIButton new];
    _comment_button.contentMode = NSTextAlignmentLeft;
    _comment_button.backgroundColor = [UIColor colorWithRed:135/255.0 green:206/255.0 blue:250/255.0 alpha:0.2];
    _comment_button.frame = CGRectMake(0, 0, (self.scrollView.frame.size.width / 3) - 40, 30);
    [_comment_button setTitle:@"评论" forState:UIControlStateNormal];
    [_comment_button setTitleColor:[UIColor colorWithRed:25/255.0 green:25/255.0 blue:112/255.0 alpha:1.0] forState:UIControlStateNormal];
    UIBezierPath * maskPath_comment = [UIBezierPath bezierPathWithRoundedRect:_comment_button.bounds cornerRadius:10];
    CAShapeLayer * maskLayer_comment = [[CAShapeLayer alloc] init];
    maskLayer_comment.frame = _comment_button.bounds;
    maskLayer_comment.path = maskPath_comment.CGPath;
    _comment_button.layer.mask = maskLayer_comment;
    [_comment_button addTarget:self
                        action:@selector(clickcommentimage:)
              forControlEvents:UIControlEventTouchUpInside];
    [self.scrollView addSubview:_comment_button];
    [_comment_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.fav_button.mas_right).offset(30);
        make.top.mas_equalTo(self.commentnum.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake((self.scrollView.frame.size.width / 3) - 40, 30));
    }];
    
    for (int i = 0; i < [jsonDictionaryOrArray[@"Data"][@"CommentNum"] intValue];i++) {
        [data_list addObject:[NSString stringWithFormat:@"%@ : %@", commentInfo[@"Data"][i][@"User"][@"Name"], commentInfo[@"Data"][i][@"Comment"][@"Content"]]];
        NSDictionary *commentJson = commentInfo[@"Data"][i];
        //NSLog(@"!!!%@\n", commentJson);
        NSArray *commentItems = [commentJson valueForKeyPath:@"Replies"];
        //NSLog(@"&&&&&%ld\n", commentItems.count);
        if (commentItems != nil && ![commentItems isKindOfClass:[NSNull class]] && commentItems.count != 0) {
            for (int j = 0; j < commentItems.count; j++) {
                [data_list addObject:[NSString stringWithFormat:@"%@ 回复 %@: %@", commentInfo[@"Data"][i][@"Replies"][j][@"User"][@"Name"],commentInfo[@"Data"][i][@"Replies"][j][@"Father"][@"Name"],  commentInfo[@"Data"][i][@"Replies"][j][@"Reply"][@"Content"]]];
            }
        }
    }
    
    CGRect rect = [[UIScreen mainScreen] bounds];
    CGSize size = rect.size;
    CGFloat width = size.width;
    _comment_tableView = [UITableView new];
    //    _comment_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 + 20,  img_start_pos_y + ((photoNum - 1) / 3 + 1) * img_offset_y, width - 40, 1000) style:UITableViewStylePlain];
    _comment_tableView.tableFooterView = [UIView new];
    _comment_tableView.delegate = self;
    _comment_tableView.dataSource = self;
    _comment_tableView.backgroundColor = [UIColor whiteColor];
    [_comment_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.scrollView addSubview:_comment_tableView];
    [_comment_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.scrollView.mas_left).offset(20);
        make.top.mas_equalTo(self.like_button.mas_bottom).offset(20);
        make.right.mas_equalTo(self.scrollView.mas_right).offset(-20);
        make.size.mas_equalTo(CGSizeMake(width - 40, 1000));
        make.bottom.equalTo(self.comment_tableView.superview.mas_bottom).offset(-30);
    }];
    
}


- (void) clicklikeimage: (UIButton *)buttonView {
    if (_like_state == NO) {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSDictionary *res = @{@"isContent":@YES,@"isComment":@NO,@"isReply":@NO};
            puts("!!!!!!!!aoligei");
            NSString *urlStr = @"http://172.18.178.56/api/like/";
            NSString *urlString = [NSString stringWithFormat:@"%@%@",urlStr, pageInfo[@"Data"][@"ID"]];
            NSURL *url = [NSURL URLWithString:urlString];
            NSError *error;
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:NSJSONWritingPrettyPrinted error:&error];
            
            NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
            [request setHTTPMethod:@"POST"];
            [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
            [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
            [request setValue:[NSString stringWithFormat:@"%lu",(unsigned long)[jsonData length]] forHTTPHeaderField:@"Content-Type"];
            [request setHTTPBody:jsonData];
            NSURLSession *session = [NSURLSession sharedSession];
            dispatch_semaphore_t semaphore= dispatch_semaphore_create(0);
            NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                                        completionHandler:^(NSData *return_data, NSURLResponse *response, NSError *error) {
                                                            
                                                            NSError *jsonError;
                                                            NSDictionary *jsonDictionaryOrArray = [NSJSONSerialization JSONObjectWithData:return_data options:kNilOptions error:&jsonError];
                                                            if(jsonError) {
                                                                // check the error description
                                                                NSLog(@"---json error : %@", [jsonError localizedDescription]);
                                                            } else {
                                                                // use the jsonDictionaryOrArray
                                                                if ([jsonDictionaryOrArray[@"State"]  isEqual: @"success"]) {
                                                                    NSLog(@"json : success");
                                                                    dispatch_async(dispatch_get_main_queue(), ^{
                                                                        data_list = [[NSMutableArray alloc] init];
                                                                        dispatch_semaphore_t semaphore_1 = dispatch_semaphore_create(0);
                                                                        NSString *urlString = [NSString stringWithFormat:@"%@%@", @"http://172.18.178.56/api/content/detail/", pageId];
                                                                        NSURL *url = [NSURL URLWithString:urlString];
                                                                        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
                                                                        request.HTTPMethod = @"GET";
                                                                        request.timeoutInterval = 60;
                                                                        NSURLSession *session = [NSURLSession sharedSession];
                                                                        NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                                                                                                    completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                                                                                        NSError *jsonError;
                                                                                                                        NSDictionary *jsonDictionaryOrArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];
                                                                                                                        if(jsonError) {
                                                                                                                            // check the error description
                                                                                                                            NSLog(@"json--- error : %@", [jsonError localizedDescription]);
                                                                                                                        } else {
                                                                                                                            // use the jsonDictionaryOrArray
                                                                                                                            NSLog(@"json : %@",jsonDictionaryOrArray);
                                                                                                                            pageInfo = jsonDictionaryOrArray;
                                                                                                                            
                                                                                                                        }
                                                                                                                        dispatch_semaphore_signal(semaphore_1);
                                                                                                                    }];
                                                                        [dataTask resume];
                                                                        
                                                                        self.view.backgroundColor = UIColor.whiteColor;
                                                                        dispatch_semaphore_wait(semaphore_1,DISPATCH_TIME_FOREVER);
                                                                        //NSLog(@"here!");
                                                                        self.navigationItem.title = @"查看打卡";
                                                                        [self setButtons];
                                                                        // [self setImgPos];
                                                                        [self setInfoByJson:pageInfo];
                                                                        //[self setInfo];
                                                                        self.scrollView.backgroundColor = UIColor.whiteColor;
                                                                        [self.view addSubview:self.scrollView];
                                                                        
                                                                    });
                                                                } else {
                                                                    NSLog(@"53545json : error");
                                                                }
                                                            }
                                                            dispatch_semaphore_signal(semaphore);
                                                        }];
            [dataTask resume];
            dispatch_semaphore_wait(semaphore,DISPATCH_TIME_FOREVER);
            self.likeimage.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"like_selected.png"] TransformtoSize:CGSizeMake(20, 20)]];
            [self.like_button setTitle:@"已点赞" forState:UIControlStateNormal];
            self.like_button.backgroundColor = [UIColor grayColor];
            self.like_state = YES;
        });
    } else {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.likeimage.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"like.png"] TransformtoSize:CGSizeMake(20, 20)]];
            [self.like_button setTitle:@"点赞" forState:UIControlStateNormal];
            self.like_button.backgroundColor = [UIColor colorWithRed:135/255.0 green:206/255.0 blue:250/255.0 alpha:0.2];
            self.like_state = NO;
        });
    }
}

- (Boolean) get_like_state {
    __block NSMutableDictionary *jsonDictionaryOrArray = [[NSMutableDictionary alloc] init];
    __block Boolean like_state_temp = NO;
    NSString *urlString = @"http://172.18.178.56/api/like";
    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"GET";
    request.timeoutInterval = 60;
    dispatch_semaphore_t semaphore= dispatch_semaphore_create(0);
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        NSError *jsonError;
        jsonDictionaryOrArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];
        if(jsonError) {
            // check the error description
            NSLog(@"json error : %@", [jsonError localizedDescription]);
        } else {
            if ([jsonDictionaryOrArray[@"State"] isEqual: @"success"]) {
                NSArray *like_l = [jsonDictionaryOrArray valueForKeyPath:@"Data"];
                for (NSInteger kk = 0; kk < like_l.count; kk++) {
                    if ([like_l[kk] isEqualToString:pageId]) {
                        NSLog(@"right: %@", like_l[kk]);
                        like_state_temp = YES;
                        break;
                    }
                }
            }
        }
        dispatch_semaphore_signal(semaphore);
    }];
    [dataTask resume];
    dispatch_semaphore_wait(semaphore,DISPATCH_TIME_FOREVER);
    return like_state_temp;
}

- (void) clickfavimage: (UIButton *)buttonView {
    if (_fav_state == NO) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.fav_button setTitle:@"已收藏" forState:UIControlStateNormal];
            self.fav_button.backgroundColor = [UIColor grayColor];
            self.fav_state = YES;
        });
    } else {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.fav_button setTitle:@"收藏" forState:UIControlStateNormal];
            self.fav_button.backgroundColor = [UIColor colorWithRed:135/255.0 green:206/255.0 blue:250/255.0 alpha:0.2];
            self.fav_state = NO;
        });
    }
}

- (void) clickcommentimage: (UIButton *)buttonView {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"评论" message:@"" preferredStyle:UIAlertControllerStyleAlert];
    //增加确定按钮；
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //获取第1个输入框；
        UITextField *userCommentTextField = alertController.textFields.firstObject;
        NSLog(@"评论 = %@",userCommentTextField.text);
        
        NSDictionary *res = @{@"contentID": pageInfo[@"Data"][@"ID"], @"fatherID":pageInfo[@"Data"][@"ID"], @"content": userCommentTextField.text, @"isReply": @NO};
        //    NSDictionary *text = [[NSDictionary alloc] initWithObjectsAndKeys: @"这是一个测试", @"title", @"天长地久有时尽，此恨绵绵无绝期" , @"detail",@"学习",@"tag",nil ];
        NSString *urlStr = @"http://172.18.178.56/api/comment";
        NSString *urlString = [NSString stringWithFormat:@"%@",urlStr];
        NSURL *url = [NSURL URLWithString:urlString];
        NSError *error;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:NSJSONWritingPrettyPrinted error:&error];
        
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
        [request setHTTPMethod:@"POST"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [request setValue:[NSString stringWithFormat:@"%lu",(unsigned long)[jsonData length]] forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:jsonData];
        NSURLSession *session = [NSURLSession sharedSession];
        dispatch_semaphore_t semaphore= dispatch_semaphore_create(0);
        NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                                    completionHandler:^(NSData *return_data, NSURLResponse *response, NSError *error) {
                                                        
                                                        NSError *jsonError;
                                                        NSDictionary *jsonDictionaryOrArray = [NSJSONSerialization JSONObjectWithData:return_data options:kNilOptions error:&jsonError];
                                                        
                                                        //NSLog(@"!!!!49635698354\n%@",jsonDictionaryOrArray);
                                                        
                                                        if(jsonError) {
                                                            // check the error description
                                                            NSLog(@"json error : %@", [jsonError localizedDescription]);
                                                        } else {
                                                            // use the jsonDictionaryOrArray
                                                            if ([jsonDictionaryOrArray[@"State"]  isEqual: @"success"]) {
                                                                NSLog(@"json : success");
                                                                dispatch_async(dispatch_get_main_queue(), ^{
                                                                    NSLog(@"!!!!kha-zix%@\n", pageId);
                                                                });
                                                            } else {
                                                                NSLog(@"json : error");
                                                            }
                                                        }
                                                        dispatch_semaphore_signal(semaphore);
                                                    }];
        [dataTask resume];
        dispatch_semaphore_wait(semaphore,DISPATCH_TIME_FOREVER);
        
        
        [data_list addObject:[NSString stringWithFormat:@"我 : %@",  userCommentTextField.text]];
        [self.comment_tableView reloadData];
    }]];
    
    //增加取消按钮；
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
    
    //定义第一个输入框；
    [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"请输入文字";
    }];
    
    [self presentViewController:alertController animated:true completion:nil];
}

- (void)setImgPos{
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 3; j++) {
            NSString *tmp_pos= NSStringFromCGRect(CGRectMake(img_start_pos_x + j * img_offset_x, img_start_pos_y + i * img_offset_y, img_width, img_height));
            [pos addObject:tmp_pos];
        }
    }
}

- (instancetype) init{
    if (self = [super init]){
        pos = [[NSMutableArray alloc] init];
    }
    return self;
}

- (void)setCardInfoByJson:(NSDictionary *)jsonDictionaryOrArray {
    
    [self.tar_card setTime:jsonDictionaryOrArray[@"Data"][@"PublishDate"]];
    [self.tar_card setExperience:jsonDictionaryOrArray[@"Data"][@"Detail"]];
    [self.tar_card setLikeNum:[jsonDictionaryOrArray[@"Data"][@"LikeNum"] intValue] ];
    [self.tar_card setCommentNum:[jsonDictionaryOrArray[@"Data"][@"CommentNum"] intValue] ];
}

- (void)viewDidLoad:(NSString*) card_id {
    [super viewDidLoad];
    _like_state = [self get_like_state];
    pageId = [[NSString alloc] initWithFormat:@"%@", card_id ];
    data_list = [[NSMutableArray alloc] init];
    dispatch_semaphore_t semaphore= dispatch_semaphore_create(0);
    NSString *urlString = [NSString stringWithFormat:@"%@%@", @"http://172.18.178.56/api/content/detail/", card_id];
    //NSString *urlString = @"http://172.18.178.56/api/content/detail/5fc788c1f5beb2def128d5ca";
    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"GET";
    request.timeoutInterval = 60;
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                    NSError *jsonError;
                                                    NSDictionary *jsonDictionaryOrArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];
                                                    if(jsonError) {
                                                        // check the error description
                                                        NSLog(@"json error : %@", [jsonError localizedDescription]);
                                                    } else {
                                                        // use the jsonDictionaryOrArray
                                                        //NSLog(@"json : %@",jsonDictionaryOrArray);
                                                        pageInfo = jsonDictionaryOrArray;
                                                        
                                                    }
                                                    dispatch_semaphore_signal(semaphore);
                                                }];
    [dataTask resume];
    dispatch_semaphore_wait(semaphore,DISPATCH_TIME_FOREVER);
    self.view.backgroundColor = UIColor.whiteColor;
    
    NSLog(@"here!");
    self.navigationItem.title = @"查看打卡";
    //[self setButtons];
    [self setInfoByJson:pageInfo];
    self.scrollView.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:self.scrollView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
}


- (void) likeBtnClick:(UIButton *)btn {
    if (addLikeNum > 0) {
        return;
    }
    addLikeNum++;
    NSDictionary *res = @{@"isContent":@YES,@"isComment":@NO,@"isReply":@NO};
    puts("!!!!!!!!aoligei");
    NSString *urlStr = @"http://172.18.178.56/api/like/";
    NSString *urlString = [NSString stringWithFormat:@"%@%@",urlStr, pageInfo[@"Data"][@"ID"]];
    NSURL *url = [NSURL URLWithString:urlString];
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:NSJSONWritingPrettyPrinted error:&error];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setValue:[NSString stringWithFormat:@"%lu",(unsigned long)[jsonData length]] forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:jsonData];
    NSURLSession *session = [NSURLSession sharedSession];
    dispatch_semaphore_t semaphore= dispatch_semaphore_create(0);
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                                completionHandler:^(NSData *return_data, NSURLResponse *response, NSError *error) {
                                                    
                                                    NSError *jsonError;
                                                    NSDictionary *jsonDictionaryOrArray = [NSJSONSerialization JSONObjectWithData:return_data options:kNilOptions error:&jsonError];
                                                    if(jsonError) {
                                                        // check the error description
                                                        NSLog(@"json error : %@", [jsonError localizedDescription]);
                                                    } else {
                                                        // use the jsonDictionaryOrArray
                                                        if ([jsonDictionaryOrArray[@"State"]  isEqual: @"success"]) {
                                                            NSLog(@"json : success");
                                                            dispatch_async(dispatch_get_main_queue(), ^{
                                                                data_list = [[NSMutableArray alloc] init];
                                                                dispatch_semaphore_t semaphore_1 = dispatch_semaphore_create(0);
                                                                NSString *urlString = [NSString stringWithFormat:@"%@%@", @"http://172.18.178.56/api/content/detail/", pageId];
                                                                NSURL *url = [NSURL URLWithString:urlString];
                                                                NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
                                                                request.HTTPMethod = @"GET";
                                                                request.timeoutInterval = 60;
                                                                NSURLSession *session = [NSURLSession sharedSession];
                                                                NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                                                                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                                                                                NSError *jsonError;
                                                                                                                NSDictionary *jsonDictionaryOrArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];
                                                                                                                if(jsonError) {
                                                                                                                    // check the error description
                                                                                                                    NSLog(@"json error : %@", [jsonError localizedDescription]);
                                                                                                                } else {
                                                                                                                    // use the jsonDictionaryOrArray
                                                                                                                    NSLog(@"json : %@",jsonDictionaryOrArray);
                                                                                                                    pageInfo = jsonDictionaryOrArray;
                                                                                                                    
                                                                                                                }
                                                                                                                dispatch_semaphore_signal(semaphore_1);
                                                                                                            }];
                                                                [dataTask resume];
                                                                
                                                                self.view.backgroundColor = UIColor.whiteColor;
                                                                dispatch_semaphore_wait(semaphore_1,DISPATCH_TIME_FOREVER);
                                                                //NSLog(@"here!");
                                                                self.navigationItem.title = @"查看打卡";
                                                                [self setCollectButton];
                                                                // [self setImgPos];
                                                                [self setInfoByJson:pageInfo];
                                                                //[self setInfo];
                                                                self.scrollView.backgroundColor = UIColor.whiteColor;
                                                                [self.view addSubview:self.scrollView];
                                                                
                                                            });
                                                        } else {
                                                            NSLog(@"json : error");
                                                        }
                                                    }
                                                    dispatch_semaphore_signal(semaphore);
                                                }];
    [dataTask resume];
    dispatch_semaphore_wait(semaphore,DISPATCH_TIME_FOREVER);
    
    // [self viewDidLoad:pageId];
    
}

- (void) collectBtnClick:(UIButton *)btn {
    
}

- (void)setLikeButton {
    likeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    likeBtn.frame = CGRectMake(0, 0, 30, 30);
    likeBtn.layer.borderColor = [UIColor grayColor].CGColor;
    likeBtn.layer.borderWidth = 1.0;
    likeBtn.layer.cornerRadius = 15.0;
    
    [likeBtn setTitle:@"点赞" forState:UIControlStateNormal];
    likeBtn.titleLabel.font = [UIFont systemFontOfSize: 10.0];
    [likeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [likeBtn addTarget:self action:@selector(likeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setCollectButton {
    collectBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    collectBtn.frame = CGRectMake(0, 0, 30, 30);
    collectBtn.layer.borderColor = [UIColor grayColor].CGColor;
    collectBtn.layer.borderWidth = 1.0;
    collectBtn.layer.cornerRadius = 15.0;
    
    [collectBtn setTitle:@"收藏" forState:UIControlStateNormal];
    collectBtn.titleLabel.font = [UIFont systemFontOfSize: 10.0];
    [collectBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [collectBtn addTarget:self action:@selector(likeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    // self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:collectBtn];
}

- (void) setButtons {
   // [self setLikeButton];
    //[self setCollectButton];
   // UIBarButtonItem *collectBtnItem =  [[UIBarButtonItem alloc] initWithCustomView:collectBtn];
    //UIBarButtonItem *likeBtnItem =  [[UIBarButtonItem alloc] initWithCustomView:likeBtn];
    //self.navigationItem.rightBarButtonItems  = @[collectBtnItem,likeBtnItem];
}

@end
